package com.heima.MyflectDemo1;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class Demo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
        Class clazz = Class.forName("com.heima.MyflectDemo1.Student");
        Constructor constructor = clazz.getConstructor();
        Student student = (Student) constructor.newInstance();
        Field name = clazz.getDeclaredField("name");
        name.setAccessible(true);
        name.set(student,"亮子");
        Field age = clazz.getDeclaredField("age");
        age.setAccessible(true);
        age.set(student,35);
        System.out.println(student);
    }
}
